﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Net.Mail;
using System.Globalization;
using Eoffice.Models;


namespace Eoffice.Controllers
{
    public class PageController : Controller
    {
        EofficeDb data = new EofficeDb();

        public ActionResult timkiem()
        {
            return View();
        }

        #region[Them dau Tieng Viet doi voi tung chu]
        public string ReplaceCharSet(string input)
        {
            string charSet = input.ToLower();
            if (charSet == "a")
                return "[aàảãáạăằẳẵắặâầẩẫấậ]";
            else if (charSet == "e")
                return "[eèẻẽéẹêềểễếệ]";
            else if (charSet == "i")
                return "[iìỉĩíị]";
            else if (charSet == "o")
                return "[oòỏõóọôồổỗốộơờởỡớợ]";
            else if (charSet == "u")
                return "[uùủũúụưừửữứự]";
            else if (charSet == "y")
                return "[yỳỷỹýỵ]";
            else if (charSet == "d")
                return "[dđ]";
            return charSet;
        }
        #endregion
        #region[Loai bo dau Tieng Viet doi voi tung chu - chuyen doi chu tu Unicode sang ASCII]
        public string RemoveUnicode(string inputText, bool sqlSearch)
        {
            string stFormD = inputText.Normalize(System.Text.NormalizationForm.FormD);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string str = "";
            for (int i = 0; i <= stFormD.Length - 1; i++)
            {
                UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[i]);
                if (uc == UnicodeCategory.NonSpacingMark == false)
                {
                    if (stFormD[i] == 'đ')
                        str = "d";
                    else if (stFormD[i] == 'Đ')
                        str = "D";
                    else
                        str = stFormD[i].ToString();
                    //Neu sqlSearch = true thi sau khi khu dau xong o tren se tien hanh them dau, con neu sqlSearch = false thi nguoc lai
                    if (sqlSearch) str = ReplaceCharSet(str);
                    sb.Append(str);
                }
            }
            return sb.ToString().ToLower();
        }
        #endregion
    }
}
